<template>
  <div class="count">
    <h2>当前求和为：{{ sum }}</h2>
    <h2>当前的学校：{{ school }}</h2>
    <h2>当前的地址：{{ address }}</h2>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">+</button>
    <button @click="minus">-</button>
    <button @click="oddAdd">当前和为奇数+</button>
    <button @click="waitAdd">等一等+</button>
    <button @click="serverAdd">问问服务器怎么+</button>
  </div>
</template>

<script>
  import { mapState } from 'vuex'
  export default {
    name:'Count',
    data() {
      return {
        n:1,
      }
    },
    computed: {
      ...mapState(['sum','school','address'])
    },
    methods: {
      // 加
      add(){
        this.$store.commit('JIA',this.n)
      },
      // 减
      minus(){
        this.$store.commit('JIAN',this.n)
      },
      // 奇数加
      oddAdd(){
        // 通过调用dispatch，去联系actions中jijia方法，且携带着数据过去
        this.$store.dispatch('jijia',this.n)
      },
      // 异步加
      waitAdd(){
        this.$store.dispatch('dengjia',this.n)
      },
      // 联系服务器去加
      serverAdd(){
        this.$store.dispatch('fuwuJia')
      },
      /* test(){
        let x = mapState(['sum','school','address'])
        console.log(x)
      } */
    },
  }
</script>

<style scoped>
  .count {
    background-color: skyblue;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
  }
  button {
    margin: 0 5px;
  }
</style>